package com.proposition.exam.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.proposition.commons.exam.result.Result;
import com.proposition.commons.exam.result.ResultUtil;
import com.proposition.commons.exam.util.ExamAddUtil;
import com.proposition.commons.exam.util.ExamFieldVolidateUtil;
import com.proposition.commons.exam.util.ExamUtil;
import com.proposition.commons.model.ExamAcupointPediatric;
import com.proposition.commons.model.ExamAcupointPediatricOriginal;
import com.proposition.exam.mapper.ExamAcupointPediatricMapper;
import com.proposition.exam.service.ExamAcupointPediatricService;
import com.proposition.support.security.CurrentUser;
import com.proposition.support.utils.UUIDUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 14:19 2017/11/2
 * @description:问答题-腧穴试题服务类接口实现类
 */
@Service
public class ExamAcupointPediatricServiceImpl extends ServiceImpl<ExamAcupointPediatricMapper,ExamAcupointPediatric> implements ExamAcupointPediatricService {

    @Transactional
    @Override
    public Result add(String[] answerXWDW1, Float[] answerXWDWScore1, ExamAcupointPediatric exam, ExamAcupointPediatricOriginal examOriginal) {
        String stem = ExamFieldVolidateUtil.getIllegalStem(exam.getStem());
        exam.setStem(stem);
        ExamAddUtil.volidateUniqueStem(exam);
        ExamUtil.volidateOutlineCode(exam.getOutlineCode());

        String categoryStr = ExamUtil.getCategoryStr(exam.getCategoryId());
        String id = UUIDUtil.getExamUUIDByCategory(categoryStr);
        String userIdImport = CurrentUser.INSTANCE.getUserId();

        for (int i = 0; i < answerXWDW1.length; i++) {
            switch (i + 1) {
                case 1:
                    exam.setLocation1Pediatric(answerXWDW1[i]);
                    examOriginal.setLocation1Pediatric(answerXWDW1[i]);
                    break;
                case 2:
                    exam.setLocation2Pediatric(answerXWDW1[i]);
                    examOriginal.setLocation2Pediatric(answerXWDW1[i]);
                    break;
                case 3:
                    exam.setLocation3Pediatric(answerXWDW1[i]);
                    examOriginal.setLocation3Pediatric(answerXWDW1[i]);
                    break;
                default:
                    break;
            }
        }
        for (int i = 0; i < answerXWDWScore1.length; i++) {
            switch (i + 1) {
                case 1:
                    exam.setLocation1ScorePediatric(answerXWDWScore1[i]);
                    examOriginal.setLocation1ScorePediatric(answerXWDWScore1[i]);
                    break;
                case 2:
                    exam.setLocation2ScorePediatric(answerXWDWScore1[i]);
                    examOriginal.setLocation2ScorePediatric(answerXWDWScore1[i]);
                    break;
                case 3:
                    exam.setLocation3ScorePediatric(answerXWDWScore1[i]);
                    examOriginal.setLocation3ScorePediatric(answerXWDWScore1[i]);
                    break;
                default:
                    break;
            }
        }

        exam.setId(id);//设置id
        exam.setUserIdImport(userIdImport);//设置当前导入用户id
        exam.insert();

        examOriginal.setId(id);
        examOriginal.setUserIdImport(userIdImport);
        examOriginal.insert();

        return ResultUtil.sucess();
    }
}
